/**
 * @fileoverview
 * TODO doc me
 */


// Shortcuts
var trace = function(message) { YAHOO.log(message, "test"); };
var assert = YAHOO.util.Assert;

// custom assertions

assert.isVisible = function(element, message) {
	assert.isFalse(YAHOO.util.Dom.hasClass(element, "invisible"), message);
}

assert.isNotVisible = function(element, message) {
	assert.isTrue(YAHOO.util.Dom.hasClass(element, "invisible"), message);
}

// ************************************************************
// MODULE TESTS
// ************************************************************

/**
 * TODO doc me
 */
flyui.bdgp.ImageWidget.ModuleTests = function(){};


/** 
 * Test that the contents of the flyui.bdgp.ImageWidget module have been defined.
 */
flyui.bdgp.ImageWidget.ModuleTests.testModuleContents = function() {
	
	flyui.info("Test \"==== flyui.bdgp.ImageWidget ModuleTests :: testModuleContents ====\" started.");
	
	assert.isNotUndefined(flyui.bdgp.ImageWidget, "flyui.bdgp.ImageWidget is undefined");	
	assert.isNotUndefined(flyui.bdgp.ImageWidget.Controller, "flyui.bdgp.ImageWidget.Controller is undefined");	
	assert.isNotUndefined(flyui.bdgp.ImageWidget.modelDefinition, "flyui.bdgp.ImageWidget.modelDefinition is undefined");	
	assert.isNotUndefined(flyui.bdgp.ImageWidget.DefaultRenderer, "flyui.bdgp.ImageWidget.DefaultRenderer is undefined");	
	
};

/**
 * TODO doc me
 */
flyui.bdgp.ImageWidget.ModuleTestCase = function (){
	var testCase = new YAHOO.tool.TestCase({
		
		name: "=== flyui.bdgp.ImageWidget ModuleTests ===",
		
		testModuleContents : flyui.bdgp.ImageWidget.ModuleTests.testModuleContents
		
	});
	
	return testCase;
}

// ************************************************************
// CONTROLLER TESTS
// ************************************************************

/**
 * TODO doc me
 */
flyui.bdgp.ImageWidget.ControllerTests = function(){};

/** 
 * Set up function for the flyui.bdgp.ImageWidget.ControllerTests.
 * @param {String} endpointURL URL of bdgp service
 * @param {YAHOO.tool.TestCase} testCase the test case context
 */
flyui.bdgp.ImageWidget.ControllerTests.setUpTest = function( endpointURL, testCase ) {
	try {
		trace("setUp test");
		// create a model
		testCase.model = new flyui.mvcutils.GenericModel2();
		testCase.model.setDefinition(flyui.bdgp.ImageWidget.modelDefinition);
	
		// create a service
		testCase.service = new flyui.bdgp.Service(endpointURL);
		
		// create a dummy widget
		testCase.dummyWidget = {};
		
		// create a new controller instance
		testCase.controller = new flyui.bdgp.ImageWidget.Controller(testCase.model, testCase.service, testCase.dummyWidget);
		
	} catch (e) {
		flyui.err("setUp error, "+e.name+", "+e.message);
	}
};


/** 
 * Tear down function for the flyui.bdgp.ImageWidget.ControllerTests.
 * @param {YAHOO.tool.TestCase} testCase the test case context
 */
flyui.bdgp.ImageWidget.ControllerTests.tearDownTest = function( testCase ) {
	try {
		trace("tearDown test");
	} catch (e) {
		flyui.err("tearDown error, "+e.name+", "+e.message);
	}
};

/**
 * Test the model definition and initialisation.
 * @synchronous
 */
flyui.bdgp.ImageWidget.ControllerTests.testModelInit = function( testCase ) {
	flyui.info("Test \"==== flyui.bdgp.ImageWidget ControllerTests :: testModelInit ====\" started.");

	// create a model
	var model = testCase.model;

	// check the model properties
	assert.areEqual("READY", model.get("STATE"));
	assert.isNull(model.get("RESULTS"));
	assert.isNull(model.get("ERRORMESSAGE"));
	assert.isNull(model.get("QUERY"));
};

/**
 * Test the Controller class constructor.
 * @param {YAHOO.tool.TestCase} testCase the test case context
 * @synchronous
 */
flyui.bdgp.ImageWidget.ControllerTests.testControllerConstructor = function( testCase ) {
	flyui.info("Test \"==== flyui.bdgp.ImageWidget ControllerTests :: testControllerConstructor ====\" started.");

	// create a new controller instance
	var controller = testCase.controller;

	// check the API
	assert.isNotUndefined(controller.findImagesByAnyGeneLabel);
		
};



flyui.bdgp.ImageWidget.ControllerTests.test_findImagesByAnyGeneLabel = function (testCase) {
	flyui.info("Test \"==== flyui.bdgp.ImageWidget ControllerTests :: test_findImagesBybdgpGeneName ====\" started.");

	// convenience variables
	var controller = testCase.controller;
	var model = testCase.model;
	
	var success = function(images){
		trace("success case, resume test runner");
		testCase.resume();
	}
	
	var failure = function (response) {
		trace("failure case, resume test runner");
		testCase.resume(function() {
			assert.fail("request failed, status "+response.status+" "+response.statusText);
		});
	}
	
	controller._findImagesByAnyGeneLabel("foo", success, failure);
	
	// check the model state property
	assert.areEqual("PENDING", model.get("STATE"));
	
	// check the model query property
	assert.areEqual("foo", model.get("QUERY"));
	
	trace("suspend test runner (hang here means problem)");
	testCase.wait();
};

/**
 * TODO doc me
 */

flyui.bdgp.ImageWidget.ControllerTests.test_findImagesSuccess = function (testCase){
	flyui.info("Test \"==== flyui.bdgp.ImageWidget ControllerTests :: test_findImagesSuccess ====\" started.");

	// convenience variables
	var controller = testCase.controller;
	var model = testCase.model;
	
	// fake up the state as pending
	model.set("STATE", "PENDING");
	
	// fake up a result set
	var images = [];
	
	// make the callback
	controller._findImagesSuccess(images);
	
	// check the state
	assert.areEqual("READY", model.get("STATE"));
//	
//	// check the results
	var results = model.get("RESULTS");
	assert.isNotUndefined(results);
	assert.isNotUndefined(results.length);
	assert.areEqual(0, results.length);
}

/**
 * TODO doc me
 */
 
flyui.bdgp.ImageWidget.ControllerTests.test_findImagesFailure = function (testCase) {
	flyui.info("Test \"==== flyui.bdgp.ImageWidget ControllerTests :: test_findImagesFailure ====\" started.");

	var controller = testCase.controller;
	var model = testCase.model;

	// fake up the state as pending
	model.set("STATE", "PENDING");
		
	// make the call
	var response = {status:999, statusText:"dummy error for testing"};
	controller._findImagesFailure(response);

	// check the state
	assert.areEqual("SERVERERROR", model.get("STATE"));
//	
//	// check the error message
	var msg = model.get("ERRORMESSAGE");
	trace("error message: "+msg);
	assert.isNotNull(msg);
}

/**
 * TODO doc me
 */
flyui.bdgp.ImageWidget.ControllerTestCase = function (endpointURL){
	var testCase = new YAHOO.tool.TestCase({
		
		name: "=== flyui.bdgp.ImageWidget ControllerTestCase ===",
		
		setUp : function() {
			flyui.bdgp.ImageWidget.ControllerTests.setUpTest(endpointURL, this);
		},
		
		tearDown : function() {
			flyui.bdgp.ImageWidget.ControllerTests.tearDownTest(this);
		},
		
		testModelInit : function() {
			flyui.bdgp.ImageWidget.ControllerTests.testModelInit(this);
		},
		
		testControllerConstructor : function() {
			flyui.bdgp.ImageWidget.ControllerTests.testControllerConstructor(this);
		}, 
		
		test_findImagesByAnyGeneLabel : function() {
			flyui.bdgp.ImageWidget.ControllerTests.test_findImagesByAnyGeneLabel(this);
		},
		
		test_findImagesSuccess : function() {
			flyui.bdgp.ImageWidget.ControllerTests.test_findImagesSuccess(this);
		},
		
		test_findImagesFailure : function() {
			flyui.bdgp.ImageWidget.ControllerTests.test_findImagesFailure(this);
		}	
		
	});
	
	return testCase;
}


// ************************************************************
// DEFAULT RENDERER TESTS
// ************************************************************


/**
 * @class
 * A collection of tests to test the DefaultRenderer class.
 */
flyui.bdgp.ImageWidget.DefaultRendererTests = function() {};


/** 
 * Set up function for the flyui.bdgp.ImageWidget DefaultRendererTests.
 * @param {YAHOO.tool.TestCase} testCase the test case context
 */
flyui.bdgp.ImageWidget.DefaultRendererTests.setUpTest = function( testCase ) {
	try {
		trace("setUp test");
		
		trace("create a model");
		testCase.model = new flyui.mvcutils.GenericModel2();
		testCase.model.setDefinition(flyui.bdgp.ImageWidget.modelDefinition);
		
		trace("create an element for the renderer");
		testCase.renderPane = document.createElement("div");
		
		trace("put the renderer's div into the dom");
		document.body.appendChild(testCase.renderPane);
		
		trace("create a renderer");
		testCase.renderer = new flyui.bdgp.ImageWidget.DefaultRenderer();
		testCase.renderer.setCanvas(testCase.renderPane);
		
		trace("connect the renderer the model");
		testCase.renderer.connect(testCase.model);
				
	} catch (e) {
		flyui.err("setUp error, "+e.name+", "+e.message);
	}
};


/** 
 * Tear down function for the flyui.bdgp.ImageWidget DefaultRendererTests.
 * @param {YAHOO.tool.TestCase} testCase the test case context
 */
flyui.bdgp.ImageWidget.DefaultRendererTests.tearDownTest = function( testCase ) {
	try {
		trace("tearDown test");
		
		trace("remove the renderer element from the dom");
		document.body.removeChild(testCase.renderPane); 
		
	} catch (e) {
		flyui.err("tearDown error, "+e.name+", "+e.message);
	}
};

/**
 * TODO doc me
 */
flyui.bdgp.ImageWidget.DefaultRendererTests.testAPI = function( testCase ) {
	flyui.info("Test \"==== flyui.	.ImageWidget DefaultRenderer Tests :: testAPI ====\" started.");
		
	var renderer = testCase.renderer;
	
	assert.isNotUndefined(renderer);
	assert.isNotUndefined(renderer.connect);

	assert.isNotUndefined(renderer._onStateChanged);
	assert.isNotUndefined(renderer._onQueryChanged);
	assert.isNotUndefined(renderer._onResultsChanged);
	assert.isNotUndefined(renderer._onErrorMessageChanged);

	// check pane fields
	assert.isNotUndefined(renderer._canvas);
	assert.isNotUndefined(renderer._pendingPane);
	assert.isNotUndefined(renderer._messagePane);
	assert.isNotUndefined(renderer._resultsSummaryPane);
	assert.isNotUndefined(renderer._resultsPane);

};

/**
 * TODO doc me
 */
flyui.bdgp.ImageWidget.DefaultRendererTests.testMainComponents = function( testCase ) {
	flyui.info("Test \"==== flyui.bdgp.ImageWidget DefaultRenderer Tests :: testMainComponents ====\" started.");

	var renderPane = testCase.renderPane;
	var renderer = testCase.renderer;
	
	var children = renderPane.childNodes;
	trace(renderPane.innerHTML);
	for ( var i=0; i<children.length; i++ ) {
		trace("found child: "+children[i]);
	}
	assert.areEqual(4, children.length, "number of child elements not as expected");
	
	trace("Check pending pane is hidden");
	assert.isNotVisible(renderer._pendingPane, "Pending pane should be invisible");
//	assert.areEqual(1, pendingPane.childNodes.length);
//	assert.areEqual("Pending...", pendingPane.childNodes[0].innerHTML);
	
	trace("Check message pane is invisible and contains text 'this should never be displayed'");
	assert.isNotVisible(renderer._messagePane, "Message pane should be invisible");
	assert.areEqual("this should never be displayed", renderer._messagePane.innerHTML);

	trace("Check results summary pane is invisible");
	assert.isNotVisible(renderer._resultsSummaryPane, "Results summary pane should be invisible");

	trace("Check results pane is invisible");
	assert.isNotVisible(renderer._resultsPane, "Results pane should be invisible");

//	trace("Check 2nd DIV using Yahoo selector for access");
//	var divs = YAHOO.util.Selector.query("div", renderPane);
//	assert.isNotVisible(divs[1], "Message div should be invisible");
//	assert.areEqual("this should never be displayed", divs[1].innerHTML);
	
};

/**
 * TODO doc me
 */
flyui.bdgp.ImageWidget.DefaultRendererTests.testModelStateChangeToPending = function( testCase ) {
	flyui.info("Test \"==== flyui.bdgp.ImageWidget DefaultRenderer Tests :: testModelStateChangeToPending ====\" started.");
	
	var renderer = testCase.renderer;
	var model = testCase.model;
	
	trace("set the model state to pending");
	model.set("STATE", "PENDING");
	
	trace("check the pending pane is visible");
	assert.isVisible(renderer._pendingPane, "Pending pane should be visible");

	trace("check the message pane is not visible");
	assert.isNotVisible(renderer._messagePane, "message pane should be invisible");

	trace("check the results summary pane is not visible");
	assert.isNotVisible(renderer._resultsSummaryPane, "results summary pane should be invisible");

	trace("check the results pane is not visible");
	assert.isNotVisible(renderer._resultsPane, "results pane should be invisible");
}

/**
 * TODO doc me
 */
flyui.bdgp.ImageWidget.DefaultRendererTests.testModelStateChangeToReady = function( testCase ) {
	flyui.info("Test \"==== flyui.bdgp.ImageWidget DefaultRenderer Tests :: testModelStateChangeToReady ====\" started.");
	
    var renderer = testCase.renderer;
    var model = testCase.model;
	
	trace("set the model state to ready");
	model.set("STATE", "READY");
	
	trace("check the pending pane is not visible");
	assert.isNotVisible(renderer._pendingPane, "Pending pane should be invisible");

	trace("check the message pane is not visible");
	assert.isNotVisible(renderer._messagePane, "message pane should be invisible");

	trace("check the results summary pane is visible");
	assert.isVisible(renderer._resultsSummaryPane, "results summary pane should be visible");

	trace("check the results pane is visible");
	assert.isVisible(renderer._resultsPane, "results pane should be visible");	
}

/**
 * TODO doc me
 */
flyui.bdgp.ImageWidget.DefaultRendererTests.testModelStateChangeToServerError = function( testCase ) {
	flyui.info("Test \"==== flyui.bdgp.ImageWidget DefaultRenderer Tests :: testModelStateChangeToServerError ====\" started.");
	
    var renderer = testCase.renderer;
    var model = testCase.model;
	
	trace("set the model state to pending");
	model.set("STATE", "PENDING");	
	
	trace("set the model state to server error");
	model.set("STATE", "SERVERERROR");
	
	trace("check the pending pane is not visible");
	assert.isNotVisible(renderer._pendingPane, "Pending pane should be invisible");

	trace("check the message pane is visible");
	assert.isVisible(renderer._messagePane, "message pane should be visible");

	trace("check the results summary pane is not visible");
	assert.isNotVisible(renderer._resultsSummaryPane, "results summary pane should be invisible");

	trace("check the results pane is not visible");
	assert.isNotVisible(renderer._resultsPane, "results pane should be invisible");
}

/**
 * TODO doc me
 */
flyui.bdgp.ImageWidget.DefaultRendererTests.testModelStateChangeToUnexpectedError = function( testCase ) {
	flyui.info("Test \"==== flyui.bdgp.ImageWidget DefaultRenderer Tests :: testModelStateChangeToUnexpectedError ====\" started.");
	
    var renderer = testCase.renderer;
    var model = testCase.model;
	
	trace("set the model state to pending");
	model.set("STATE", "PENDING");	
	
	trace("set the model state to unexpected error");
	model.set("STATE", "UNEXPECTEDERROR");
	
	trace("check the pending pane is not visible");
	assert.isNotVisible(renderer._pendingPane, "Pending pane should be invisible");

	trace("check the message pane is visible");
	assert.isVisible(renderer._messagePane, "message pane should be visible");

	trace("check the results summary pane is not visible");
	assert.isNotVisible(renderer._resultsSummaryPane, "results summary pane should be invisible");

	trace("check the results pane is not visible");
	assert.isNotVisible(renderer._resultsPane, "results pane should be invisible");
};

/**
 * TODO doc me
 */
flyui.bdgp.ImageWidget.DefaultRendererTests.testZeroResults = function( testCase ) {
	flyui.info("Test \"==== flyui.bdgp.ImageWidget DefaultRenderer Tests :: testZeroResults ====\" started.");
	
	var renderer = testCase.renderer;
	var model = testCase.model;
	var summaryPane = renderer._resultsSummaryPane;
	var resultsPane = renderer._resultsPane;
	var images = [];
	
	trace("set the model query");
	model.set("QUERY", "foo");
	
	trace("set the model results");
	model.set("RESULTS", images);
	
    trace("set the model state");
    model.set("STATE", "READY");
    	
	trace("checking the results summary pane");
	flyui.bdgp.ImageWidget.assertResultsSummaryPaneAsExpected(0, "foo", summaryPane);

	trace("checking the results pane");
	flyui.bdgp.ImageWidget.assertResultsPaneAsExpected(images, resultsPane);
	
};

/**
 * TODO doc me
 */
flyui.bdgp.ImageWidget.DefaultRendererTests.testOneResult = function( testCase ) {
	flyui.info("Test \"==== flyui.bdgp.ImageWidget DefaultRenderer Tests :: testOneResult ====\" started.");
	
    var renderer = testCase.renderer;
	var model = testCase.model;
	var summaryPane = renderer._resultsSummaryPane;
	var resultsPane = renderer._resultsPane;
	
	var testData = new flyui.bdgp.Service.TestData;
	var stages = [testData.stage_CG10561];
		
	trace("set the model query");
	model.set("QUERY", "CG10561");
	
	trace("set the model results");
	model.set("RESULTS", stages);
	
    trace("set the model state");
    model.set("STATE", "READY");
	
	trace("checking the results summary pane");
	flyui.bdgp.ImageWidget.assertResultsSummaryPaneAsExpected(1, "CG10561", summaryPane); //TODO

	trace("checking the results pane");
	flyui.bdgp.ImageWidget.assertResultsPaneAsExpected(stages, resultsPane);
	
};

flyui.bdgp.ImageWidget.DefaultRendererTests.testTwoResults = function( testCase ) {
	flyui.info("Test \"==== flyui.bdgp.ImageWidget DefaultRenderer Tests :: testTwoResults ====\" started.");
	
    var renderer = testCase.renderer;
	var model = testCase.model;
	var summaryPane = renderer._resultsSummaryPane;
	var resultsPane = renderer._resultsPane;
	var testData = new flyui.bdgp.Service.TestData;
	var images = [testData.stage_CG12750_1, testData.stage_CG12750_2, testData.stage_CG12750_3,testData.stage_CG12750_4,testData.stage_CG12750_5];
	
	trace("set the model query");
	model.set("QUERY", "CG12750");
	
	trace("set the model results");
	model.set("RESULTS", images);

    trace("set the model state");
    model.set("STATE", "READY");
    	
	trace("checking the results summary pane");
	flyui.bdgp.ImageWidget.assertResultsSummaryPaneAsExpected(11, "CG12750", summaryPane);

	trace("checking the results pane");
	flyui.bdgp.ImageWidget.assertResultsPaneAsExpected(images, resultsPane);
		
}


/**
 * TODO doc me
 */
flyui.bdgp.ImageWidget.DefaultRendererTests.testSetErrorMessage = function( testCase ) {
	flyui.info("Test \"==== flyui.bdgp.ImageWidget.DefaultRenderer Tests :: testSetErrorMessage ====\" started.");
	
	var renderer = testCase.renderer;
	var model = testCase.model;
	var messagePane = renderer._messagePane;

	var msg = "this is a test error message";
	model.set("ERRORMESSAGE", msg);
	
	assert.areEqual(msg, messagePane.innerHTML);
};


/**
 * TODO doc me
 */
flyui.bdgp.ImageWidget.assertResultsSummaryPaneAsExpected = function( count, query, summaryPane ) {
	trace("checking the results summary pane");
	trace(summaryPane.innerHTML);
	
	assert.isVisible(summaryPane, "summary pane not visible");

	/* check the results summary pane
	 * expect something like...
	 * <div>Found <span>2</span> results for gene "<span>rbf</span>"</div>
	 */
//	var spans = YAHOO.util.Selector.query("span", summaryPane);
//	assert.areEqual(2, spans.length);
//	assert.areEqual(count, spans[0].innerHTML);
//	assert.areEqual(query, spans[1].innerHTML);
    assert.isTrue(summaryPane.innerHTML.indexOf(query)>0, "query doesn't appear in summary pane");
    assert.isTrue(summaryPane.innerHTML.indexOf(count)>0, "count doesn't appear in summary pane");
	
};


/**
 * TODO doc me
 */
flyui.bdgp.ImageWidget.assertResultsPaneAsExpected = function( stages, resultsPane ) {
	
	if (stages.length > 0) {
	
		/* check the results pane
		 * expect something like...
		 * <div>
		 *   <div class="result">
		 *     <a href="">
		 *       <img src="" alt="this is an image"/>
		 * 	   </a>
		 *     </div>
		 *     ...
		 * </div>
		 */
		 
		trace(resultsPane.innerHTML);
		var rows = YAHOO.util.Selector.query("tr", resultsPane);
				
		var resultNodes = YAHOO.util.Selector.query("div.result", resultsPane);		
		var lastResultNodeTested = 0;
		
		trace("check the rendered result headings");
		trace(rows[0].innerHTML);
		var th = YAHOO.util.Selector.query("th", rows[0]);
		assert.areEqual(2, th.length, "the number of headers not right");
		
		assert.areEqual(stages.length+1, rows.length, "the number of stage not right"); // expect same number of stage objects		
		for ( var s = 0; s<stages.length; s++ ){			
			var row = rows[s+1];
			var cells  = YAHOO.util.Selector.query("td", row);
			var stageNode = cells[0];
			flyui.info("checking rendered result row "+(s+1)+": "+stageNode.innerHTML);
									
			var images = stages[s].images;
			
			for ( var i=0; i<images.length; i++ ) {
				flyui.info("checking rendered result "+(i+1)+": "+resultNodes[lastResultNodeTested+i].innerHTML);						
				flyui.bdgp.ImageWidget.assertImageDivAsExpected(images[i], resultNodes[lastResultNodeTested+i]); 
			}
			lastResultNodeTested += images.length; 	
		}

	}
	else {
		assert.areEqual("", resultsPane.innerHTML); // if no images, pane is empty
	}
		
};

flyui.bdgp.assertImageTableRowAsExpected = function( stage, row ) {
	trace("check the rendered result values");
	trace(row.innerHTML);

	/*
	 * expect something like...
	 * <tr><td>stage1-3</td><td></td></tr>
	 */
	var cells  = YAHOO.util.Selector.query("td", row);
	assert.areEqual(2, cells.length, "number of table cells not as expected");
	assert.areEqual(stage.stageName.join(" / "), cells[0].innerHTML);
	
	var lastResultNodeTested = 0;
	
	var images = stage.images;
	
	for ( var i=0; i<images.length; i++ ) {
		flyui.info("checking rendered result "+(i+1)+": "+resultNodes[lastResultNodeTested+i].innerHTML);						
		flyui.bdgp.ImageWidget.assertImageDivAsExpected(images[i], resultNodes[lastResultNodeTested+i]); 
	}
	lastResultNodeTested += images.length; 	

};


/**
 * TODO doc me
 */
flyui.bdgp.ImageWidget.assertImageDivAsExpected = function (image, resultDivNode) {
	trace("check the rendered result values");
		
	/*
	 * expect something like...
	 * <a href=""><img src="" alt="this is an image"></a>
	 */
	
	var linkNode = resultDivNode.childNodes[0];
	assert.areEqual(image.fullImageURL, linkNode.href);
	
	log ("image hyperlink: "+ linkNode.innerHTML, "test");
	
	var imgNode = linkNode.childNodes[0];
	log ("thumbnail " + imgNode.src, "test");
	assert.areEqual(image.thumbnailURL, imgNode.src);
		
}

flyui.bdgp.ImageWidget.assertStageDivAsExpected = function (stage, stageDivNode) {
	trace("check the rendered development stage values");
		
	assert.areEqual(stage, stageDivNode.innerHTML);
	
	log ("development stage: "+ stageDivNode.innerHTML, "test");
		
}


/** 
 * Construct a YUI test case for the flyui.bdgp.ImageWidget DefaultRendererTests.
 * @return a YUI test case
 * @type YAHOO.tool.TestCase
 */
flyui.bdgp.ImageWidget.DefaultRendererTestCase = function() {
	
	var testCase = new YAHOO.tool.TestCase({
		
		name: "=== flyui.bdgp.ImageWidget DefaultRenderer Tests ===",
		
		setUp : function() {
			flyui.bdgp.ImageWidget.DefaultRendererTests.setUpTest(this);
		},
		
		tearDown : function() {
			flyui.bdgp.ImageWidget.DefaultRendererTests.tearDownTest(this);
		},
		
		testAPI : function() {
			flyui.bdgp.ImageWidget.DefaultRendererTests.testAPI(this);
		},
		
		testMainComponents : function(){
			flyui.bdgp.ImageWidget.DefaultRendererTests.testMainComponents(this);
		},
		
		testModelStateChangeToPending : function(){
			flyui.bdgp.ImageWidget.DefaultRendererTests.testModelStateChangeToPending(this);
		},
		
		testModelStateChangeToReady : function(){
			flyui.bdgp.ImageWidget.DefaultRendererTests.testModelStateChangeToReady(this);
		},
		
		testModelStateChangeToServerError : function(){
			flyui.bdgp.ImageWidget.DefaultRendererTests.testModelStateChangeToServerError(this);
		},
		
		testModelStateChangeToUnexpectedError : function() {
			flyui.bdgp.ImageWidget.DefaultRendererTests.testModelStateChangeToUnexpectedError(this);
		},
		
		testZeroResults : function() {
			flyui.bdgp.ImageWidget.DefaultRendererTests.testZeroResults(this);
		},
		
		testOneResult : function() {
			flyui.bdgp.ImageWidget.DefaultRendererTests.testOneResult(this);
		},
		
		testTwoResults : function(){
			flyui.bdgp.ImageWidget.DefaultRendererTests.testTwoResults(this);
		}, 
		
		testSetErrorMessage : function() {
			flyui.bdgp.ImageWidget.DefaultRendererTests.testSetErrorMessage(this);
		}
				
	});
	
	return testCase;
	
};



// ************************************************************
// TEST SUITE AND RUNNER
// ************************************************************


/** 
 * Construct a YUI test suite for the flyui.bdgp.ImageWidget module.
 * @param {String} endpointURL URL of bdgp service
 * @return a YUI test suite
 * @type YAHOO.tool.TestSuite
 */
flyui.bdgp.ImageWidget.TestSuite = function(endpointURL) {
	var suite = new YAHOO.tool.TestSuite("== flyui.bdgp.ImageWidget Test Suite ==");
	log (endpointURL, "test");
	suite.add(flyui.bdgp.ImageWidget.ModuleTestCase());
	suite.add(flyui.bdgp.ImageWidget.ControllerTestCase(endpointURL));
	suite.add(flyui.bdgp.ImageWidget.DefaultRendererTestCase());
	return suite;
}

/** 
 * Run the flyui.bdgp.ImageWidget test suite.
 * @param {String} endpointURL URL of bdgp service
 */
flyui.bdgp.ImageWidget.runTests = function(endpointURL) {
	trace("flyui.bdgp.ImageWidget :: running tests");
	YAHOO.tool.TestRunner.add(flyui.bdgp.ImageWidget.TestSuite(endpointURL));
	YAHOO.tool.TestRunner.run();
}